package com.alibaba.algo.exception;

import lombok.Getter;

@Getter
public enum SysPolicyErrorCode {

    policyAlreadyAttach(31100, "权限已被授予过该角色"),
    policyNotExist(31101, "权限不存在"),
    policyAlreadyExist(31102, "权限已存在"),
    appNotExist(31107, "应用不存在"),
    policyAlreadyUsed(31105, "权限仍在被使用"),
    paramsInvalid(31108, "参数错误"),
    /**
     * 兼容老错误码使用下划线写法
     */
    UNKNOW_ERROR(31106, "未知错误"),
    BATCH_ADD_AND_ATTACH_POLICY_ERROR(31103, "批量添加和授权失败");

    private Integer code;

    private String message;

    public static SysPolicyErrorCode valueOf(Integer code) {
        for (SysPolicyErrorCode ele : values()) {
            if(ele.getCode().equals(code)) return ele;
        }
        return null;
    }

    SysPolicyErrorCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
}
